#include "hikari.h"
#include "IrrlichtInitializer.h"


IrrlichtInitializer::IrrlichtInitializer(){
}


IrrlichtInitializer::~IrrlichtInitializer(){
}

IrrlichtDevice*IrrlichtInitializer::createIrrlichtDevice(wstring path){
	SIrrlichtCreationParameters params;
	HikariFileReader reader(path);
	FileSection*section=reader.readSection(reader.getChunk(L"deviceProperties"));
	vector<Chunk*>chunks=section->getAllAttributes();
	int width=800;
	int height=600;
	for(unsigned int i=0;i<chunks.size();i++){
		Chunk*chunk=chunks[i];
		if(Utils::equal(chunk->getName(), L"driver")){
			params.DriverType=(video::E_DRIVER_TYPE)section->readLong(chunk);
		}else if(Utils::equal(chunk->getName(), L"antialias")){
			params.AntiAlias=(int)section->readInt(chunk);
		}
		else if(Utils::equal(chunk->getName(), L"bpp")){
			params.Bits=section->readInt(chunk);
		}
		else if(Utils::equal(chunk->getName(), L"width")){
			width=section->readInt(chunk);
		}
		else if(Utils::equal(chunk->getName(), L"height")){
			height=section->readInt(chunk);
		}
		else if(Utils::equal(chunk->getName(), L"zBuffer")){
			params.ZBufferBits=section->readInt(chunk);
		}
		else if(Utils::equal(chunk->getName(), L"doubleBuffer")){
			params.Doublebuffer=section->readBoolean(chunk);
		}
		else if(Utils::equal(chunk->getName(), L"multThread")){
			params.DriverMultithreaded=section->readBoolean(chunk);
		}
		else if(Utils::equal(chunk->getName(), L"fullscreen")){
			params.Fullscreen=section->readBoolean(chunk);
		}
		else if(Utils::equal(chunk->getName(), L"srgb")){
			params.HandleSRGB=section->readBoolean(chunk);
		}
		else if(Utils::equal(chunk->getName(), L"precissionFpu")){
			params.HighPrecisionFPU=section->readBoolean(chunk);
		}
		else if(Utils::equal(chunk->getName(), L"stensilBuffer")){
			params.Stencilbuffer=section->readBoolean(chunk);
		}
		else if(Utils::equal(chunk->getName(), L"stereoBuffer")){
			params.Stereobuffer=section->readBoolean(chunk);
		}
		else if(Utils::equal(chunk->getName(), L"vsync")){
			params.Vsync=section->readBoolean(chunk);
		}
		else if(Utils::equal(chunk->getName(), L"perfTimer")){
			params.UsePerformanceTimer=section->readBoolean(chunk);
		}
		else if(Utils::equal(chunk->getName(), L"useAlpha")){
			params.WithAlphaChannel=section->readBoolean(chunk);
		}
	}

	delete section;
	section=NULL;
	params.WindowSize=core::dimension2du(width, height);
	IrrlichtDevice*device=createDeviceEx(params);
	return device;
}
